﻿<%@ WebHandler Language="C#" Class="Image" %>

using System;
using System.Web;
using Jumpton.SFA.Server.BusinessRule;
using System.IO;

public class Image : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ClearContent();
        context.Response.ContentType = "image/Gif";
        String ImagePath = System.Configuration.ConfigurationManager.AppSettings["ImagePath"];
        try
        {
            var photo = new PhotoManager().Load(context.Request.QueryString.ToString());
            if (photo != null)
            {
                String FileName = ImagePath + "\\" +photo.PHOTOPATH;
                if (File.Exists(FileName))
                {
                    FileStream stream = null;
                    try
                    {
                        stream = File.OpenRead(FileName);
                        byte[] data = new byte[stream.Length];
                        stream.Read(data, 0, data.Length);
                        context.Response.BinaryWrite(data);
                        context.Response.Flush();
                    }
                    finally
                    {
                        if (stream != null)
                        {
                            stream.Close();
                            stream.Dispose();
                            stream = null;
                        }
                    }

                }
            }

        }
        catch { }
        
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}